<template>
	<view class="writeOff_box">
		<view class="topPart">
			<view class="searchBox2 w dpflxr">
				<view class="icon">
					<image
						src="https://babybear-fx.oss-cn-shenzhen.aliyuncs.com/VIPxcx/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%9B%BE%E7%89%87/icon_search.png">
					</image>
				</view>
				<input class="inputBox" type="text" placeholder="请输入姓名或手机号" :value="search_value" @confirm="screen"
					confirm-type="search" placeholder-style="font-size:24rpx; line-height:60rpx;color:#999;"></input>
			</view>
		</view>
		<navigator class="userInfo w card" :url="'../index_transaction_detail/index_transaction_detail?id=' + item.id" hover-class="none"
			v-for="(item, index) in list">
			<view class="title_box4">
				<view class="tb_left">
					<view class="icon">
						<image src="../../static/images/icon_ddbh.png" mode="aspectFill"></image>
					</view>
					<view class="words dpflxr">
						<text class="name">{{ item.customer.userName }}</text>
						<text class="number">{{ item.orderSn }}</text>
					</view>
				</view>
			</view>
			<view class="dpflxrjb">
				<view class="ifItem">
					<text class="title">用户姓名:</text>
					<text>{{ item.customer.userName }}</text>
				</view>
				<view class="ifItem">
					<text class="title">手机号码:</text>
					<text>{{ item.customer.mobile }}</text>
				</view>
				<view class="ifItem">
					<text class="title">核销员:</text>
					<text>{{ item.employeeDto != null ? item.employeeDto.firstname + item.employeeDto.lastname : '' }}</text>
				</view>
				<view class="ifItem">
					<text class="title">时间:</text>
					<text>{{ item.createdAt }}</text>
				</view>
			</view>
		</navigator>
	</view>
</template>

<script>
	import request from "@/api/index.js";

	export default {
		data() {
			return {
				page: 1,
				search_value: '',
				list: [],
			}
		},

		onLoad() {
			this.getList(1, '', list => {
				if (list.length > 0) {
					this.list = list;
				} else {
					uni.showToast({
						title: '暂无更多数据',
						icon: 'none'
					})
				}
			})
		},

		onReachBottom() {
			var list = this.list;
			var page = this.page;
			var search_value = this.search_value;
			var incPage = ++page;

			this.getList(page, search_value, list_data => {
				if (list_data.length > 0) {
					list_data.forEach(function(val) {
						list.push(val)
					})

					this.list = list;
					this.page = incPage;
				} else {
					uni.showToast({
						title: '暂无更多数据',
						icon: 'none'
					})
				}
			});
		},

		methods: {
			getList: function(page, search_value, callback) {
				var url = '/shop/store-api/frontOrderform/' + uni.getStorageSync('shop_id') + '/page?current=' + page +
					'&customerMobile=' + search_value + '&customerName=' + search_value;

				request.http(url, 'GET').then(res => {
					var data = res.data;
					if (data.code == 0) {
						var list = data.data.records;
						callback(list);
					}
				});
			},
			
			screen: function(e) {
				var search_value = e.detail.value;
				var page = 1;

				this.page = page;
				this.search_value = search_value;

				this.getList(page, search_value, list => {
					if (list.length > 0) {
						this.list = list;
					} else {
						this.list = [];
						uni.showToast({
							title: '暂无更多数据',
							icon: 'none'
						})
					}
				})

			}
		}
	}
</script>

<style src="../../static/css/app.css"></style>
<style>
	page {
		padding-bottom: 20rpx;
	}

	.card {
		border-radius: 20rpx;
	}

	.topPart {
		background-color: #FFFFFF;
		padding: 20rpx 0rpx;
	}

	.userInfo {
		box-sizing: border-box;
		padding: 30rpx 30rpx 6rpx 30rpx;
	}

	.title_box4 {

		padding-bottom: 30rpx;
		margin-bottom: 24rpx;
	}

	.title_box4 .tb_left .icon {
		width: 40rpx;
		height: 40rpx;
		border-radius: 0;
	}

	.title_box4 .tb_left .name {
		font-size: 28rpx;
		line-height: 28rpx;
		font-weight: bold;
	}

	.title_box4 .tb_left .words .icon {
		width: 36rpx;
		height: 36rpx;
		border-radius: 0rpx;
		margin-left: 20rpx;

	}

	.title_box4 .tb_left .words .number {
		font-size: 28rpx;
		font-weight: bold;
		color: #F9600D;
		line-height: 28rpx;
		margin-left: 10rpx;
	}

	.title_box4 .tb_left .words {
		color: #333;
		height: 40rpx;
	}

	.userInfo .ifItem {
		width: 50%;
		line-height: 36rpx;
		margin-bottom: 18rpx;
	}

	.userInfo .ifItem .title {
		color: #999;
		display: block;
	}
</style>
